package com.sun.showcase.controller.mall;

import com.sun.showcase.biz.mall.service.ClassifyService;
import com.sun.showcase.client.domain.mall.Classify;
import com.sun.showcase.client.query.mall.ClassifyQuery;
import com.sun.showcase.pojo.DataGrid;
import com.sun.showcase.pojo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping(value="/mall/classify")
public class ClassifyController{
	
	@Autowired
	private ClassifyService classifyService;
	
	private Result result = new Result();
	/**
	 * 跳转到Classify管理页面
	 * 
	 * @return
	 */
	@RequestMapping(value="goClassify")
	public String goClassify() {
		return "mall/classify";
	}
	/**
	 * 跳转到Classify新增页面
	 * 
	 * @return
	 */
	@RequestMapping(value="handleClassify")
	public String handleClassify(@RequestParam(value="id",required=false) Long id , ModelMap map) {
		return "mall/classify_rowEdit";
	}

	/**
	 * 跳转到查看desc页面
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="showDesc")
	public Classify showDesc(ClassifyQuery classifyQuery) {
		return classifyService.get(classifyQuery);
	}

	/**
	 * 获得分页数据表格
	 */
	@ResponseBody
	@RequestMapping(value = "/datagrid")
	public DataGrid datagrid(ClassifyQuery classifyQuery) {
		classifyQuery.setOrderColum("order_num");
		classifyQuery.setOrderRule("asc");
		return classifyService.datagrid(classifyQuery);
	}
	

	/**
	 * 添加一个Classify
	 */
	@ResponseBody
	@RequestMapping(value="add")
	public Result add(ClassifyQuery classifyQuery) {
		classifyService.add(classifyQuery);
		result.setSuccess(true);
		result.setMsg("添加成功！");
		return result;
	}

	/**
	 * 编辑Classify
	 */
	@ResponseBody
	@RequestMapping(value="edit")
	public Result edit(ClassifyQuery classifyQuery) {
		classifyService.update(classifyQuery);
		result.setSuccess(true);
		result.setMsg("编辑成功！");
		return result;
	}

	/**
	 * 物理删除Classify
	 */
	@ResponseBody
	@RequestMapping(value="delete")
	public Result delete(ClassifyQuery classifyQuery) {
		classifyService.delete(classifyQuery.getIds());
		result.setSuccess(true);
		result.setMsg("删除成功！");
		return result;
	}
	
	/**
	 * 逻辑删除Classify
	 */
	@ResponseBody
	@RequestMapping(value="deletePt")
	public Result deletePt(ClassifyQuery classifyQuery) {
		classifyService.deletePt(classifyQuery.getIds());
		result.setSuccess(true);
		result.setMsg("删除成功！");
		return result;
	}
	/**
	 * 全部数据Classify
	 */
	@ResponseBody
	@RequestMapping(value="listAll")
	public Result listAll(ClassifyQuery classifyQuery) {
		List<ClassifyQuery> list = classifyService.listAll(classifyQuery);
		result.setSuccess(true);
		result.setMsg("成功！");
		result.setData(list);
		return result;
	}
	/**
	 * 全部数据Classify
	 */
	@ResponseBody
	@RequestMapping(value="listAll2")
	public Result listAll2(ClassifyQuery classifyQuery) {
		List<ClassifyQuery> list = classifyService.list4App(null);
		result.setSuccess(true);
		result.setMsg("成功！");
		result.setData(list);
		return result;
	}
}
